package com.halflife.framework.generator.template.simple;

import com.halflife.framework.generator.annotation.QueryAnn;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zhaoyf on 2018/8/25.
 */
public  class OperatePageAnalysis extends  BaseAnalysis{
    public OperatePageAnalysis(Class clazz) {
        super(clazz);
    }

    @Override
    public void setDataMap() {
        List<Map<String, String>> list = new ArrayList<Map<String, String>>();

        for(Field f:this.fields){
            if(f.getModifiers()== Modifier.PRIVATE || f.getModifiers()== Modifier.PROTECTED){
                if(f.getAnnotation(QueryAnn.class)==null){
                    continue;
                }
                if (f.getType().getPackage().getName().indexOf("com.halflife") > -1) {
                    continue;
                }
                Map<String, String> pmap = new HashMap<String, String>();
                pmap.put("fieldName", f.getName());

                pmap.put("propertyName", f.getAnnotation(QueryAnn.class).value());

                list.add(pmap);
                //p.setMemo(f.getDeclaredAnnotations()[0].toString());
            }

        }
        dataMap.put("size", (int)Math.ceil(Double.valueOf(list.size())/2));
        dataMap.put("listSize", list.size());
        dataMap.put("pros", list);
    }
    protected String getTemplateFile(){
        return "operatePage.ftl";
    }
    protected  String getFileDir(){
        return this.webLocation+"/"+this.dataMap.get("objectName")+"/";
    }

    protected String getFileName() {
        return "operate.html";
    }
}
